﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.Runtime.Serialization;

namespace Database
{
   
    interface DataBaseImpl
    {
        ////////////////////////   DataBase    /////////////////////////

        //  return SortedDictionary <int, string> : int -> id, string -> the forums titles
        SortedDictionary<int, string> dataBasetoString();
        
        SortedDictionary<int, Forum> getForums();
       
        User getDirector();
        
        int getNumOfForums();
        //////////////////////////     Forum   ////////////////////////////// 
        
        Forum getForum(int forumId);

        // admin ->will be the manager of the forum.
        int addForum(string title, User admin, int type);
        
        string getForumTitle(int forumId);
        
        void setForumTitle(int forumId, string title);
        
        User getForumAdmin(int forumId);

        // Return all users.
        SortedDictionary<string, User> getForumUsers(int forumId);

        int getForumType(int forumId);

        /////////////////////////     SubForum  /////////////////////////////////////////


        // in success return subforum id, otherwise -1 , moderator == admin of the forum.
        int addSubForum(int forumId, string title);
        
        SubForum getSubForum(int forumId, int subForumId);
        
        bool removeSubForum(int forumId, int subForumId);
       
        void setSubForumTitle(int forumId, int subForumId, string title);
        
        string getSubForumTitle(int forumId, int subForumId);
              
        bool removeSubForumModerator(int forumId, int subForumId, string uname);
        
        SortedDictionary<string, User> getSubForumModerators(int forumId, int subForumId);

 /*       // +++ (להתלונן) increment moderator complaint by 1
        void complaint(int forumId, int subForumId, string uname);
  */      
        SortedDictionary<int, Thread> getSubForumThreads(int forumId, int subForumId);

  /////////////////////////////////////      Threads      ///////////////////////////////////////////////////////////

        Thread getThread(int forumId, int subForumId, int threadId);

        // in success return thread id, otherwise -1
        int addThread(int forumId, int subForumId, string title, string body, User user);

        // in success return true, otherwise false
        bool removeThread(int forumId, int subForumId, int threadId);
        
        void setThreadTitle(int forumId, int subForumId, int threadId, string title);
        
        string getThreadTitle(int forumId, int subForumId, int threadId);
        
        void setThreadBody(int forumId, int subForumId, int threadId, string body);
        
        string getThreadBody(int forumId, int subForumId, int threadId);
        
        DateTime getThreadCTime(int forumId, int subForumId, int threadId);
        
        SortedDictionary<int, Post> getThreadPosts(int forumId, int subForumId, int threadId);
        
        User getThreadPublishUser(int forumId, int subForumId, int threadId);

///////////////////////////////////////////     Posts     /////////////////////////////////////////////////////
       
        // in success return subforum id, otherwise -1
        int addPost(int forumId, int subForumId, int threadId, string title, string body, User user);
        
        bool removePost(int forumId, int subForumId, int threadId, int postId);
        
        Post getPost(int forumId, int subForumId, int threadId, int postId);
        
        void setPostTitle(int forumId, int subForumId, int threadId, int postId, string title);
        
        string getPostTitle(int forumId, int subForumId, int threadId, int postId);
        
        void setPostBody(int forumId, int subForumId, int threadId, int postId, string body);
        
        string getPostBody(int forumId, int subForumId, int threadId, int postId);
        
        User getPostCreatorUser(int forumId, int subForumId, int threadId, int postId);

 //////////////////////////////////////////        Users       ///////////////////////////////////////////////
        //  Register a new user.
        User registerUser(int forumId, string uname, string name, string lastName, string password, string email);

        // Register a new user.
        User registerUser(int forumId, User user);

        // Check if user with user name = uname already exist in forum (for registry).
        bool containsUser(int forumId, string user);

        bool isForumUser(int forumId, User user);
 
        bool isSubForumModerator(int forumId, int subForumId, User user);
 
        bool isSubForumModerator(int forumId, int subForumId, string user);

        //  Return user with user name = uname.
        User getUser(int forumId, string uname);

        //  Check if user is a member (for login).
        bool isMember(int forumId, string username, string password);
        
        string getLastName(int forumId, string username);
        
        string getEmail(int forumId, string username);
        
        // Return the user's friends. 
        SortedDictionary<string, User> getFriends(int forumId, string username);

        bool addFriend(int forumId, string username, string friend);
        
        bool removeFriend(int forumId, string username, string friend);
       
        int getModeratorComplaints(int forumId, int subForumId, User moderator);
        
        int getModeratorComplaints(int forumId, int subForumId, string moderator);

        // remove moderator in sub forum. Return true in success, otherwise false.
        bool removeModerator(int forumId, int subForumId, string m_name);

        bool addSubForumModerator(int forumId, int subForumId, string uname);

        void setModeratorComplaints(int forumId, int subForumId, string moderator, int complaint);

        bool containsMail(int forumId, string email);

        bool containForbiddenWord(int forumId, string word);

        void addForbiddenWord(int forumId, string word);

        SortedDictionary<string, string> getForbiddenWords(int forumId);
        ////////////////////              Permissions         ///////////////////////////////

        //only director has permission to add new forum (add new forum)
        bool addForumPermission(User user);

        //only director and admin of the forum have permission to change forum (set title)
        bool changeForumPermission(int forumId, User user);

        //only director and admin of the forum have permission to change subforum (add and remove subforum, change title, remove moderator, add moderator)
        bool changeSubForumPermission(int forumId, User user);

        //only director, admin , moderator or publish user of the subforum have permission to change thread (add and remove thread, change title and body,  )
        bool changeThreadPermission(int forumId, int subforumId, int threadId, User user);

        //all regestred users have permission to publish thread 
        bool addThreadPermission(int forumId, User user);

        //only director, admin , moderator (in subforum) or publish user of the post have permission to change post (add and remove post, change title and body,  )
        bool changePostPermission(int forumId, int subforumId, int threadId, int postId, User user);

        //all regestred users have permission to publish post
        bool addPostPermission(int forumId, User user);

    }
}
